package com.miuu.springcloud.controller;

import com.miuu.springcloud.entry.Product;
import com.miuu.springcloud.result.JsonResult;
import com.miuu.springcloud.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.transform.Result;

@RestController
@Slf4j
@RequestMapping("/")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 查询
     * @param id
     * @return
     */
    @GetMapping("product/provider/get/{id}")
    public JsonResult selectById(@PathVariable("id") Long id){
        return JsonResult.ok(200, "查询成功", productService.selectById(id));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("product/provider/delete/{id}")
    public JsonResult deleteById(@PathVariable("id") Long id){
        return JsonResult.ok(200, "删除成功", productService.deleteById(id));
    }

    /**
     * 修改
     * @param product
     * @return
     */
    @PostMapping("product/provider/update")
    public JsonResult updateById(@RequestBody Product product){
        return JsonResult.ok(200, "修改成功", productService.updateById(product.getId(), product.getName()));
    }

    /**
     * 新增
     * @return
     */
    @PutMapping( "product/provider/add")
    public JsonResult insertById(@RequestBody Product product){
        return new JsonResult(200, "修改成功", productService.insertOne(product));
    }
}
